package homework_java.shape;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

class Student implements Comparable{
    String sname;
    int sno;
    String smajor;
    Student(String a,int b,String c){
        sname=a;
        sno=b;
        smajor=c;
    }
    @Override
	public String toString() {
		return "student: [id=" + sno + ", name=" + sname+ "," + "smajor=" +smajor+"]";
	}
    @Override
    public boolean equals(Object obj) {
		Student p = (Student)obj;
		return new EqualsBuilder().append(this.sno, p.sno).isEquals();
    }
    @Override
	public int hashCode() {
        return new HashCodeBuilder().append(this.sno).toHashCode();
    }
    @Override
    public int compareTo(Object o) {//比较string类型
        Student ss=(Student)o;
        return this.sno-ss.sno;
    }
}
class StudentManager{
    public static ArrayList<Student> stuList = new ArrayList<Student>();
    public boolean addStudent(Student s) {
        if (stuList.contains(s)) {
            System.out.println("重复");
            return false;
        } else {
            stuList.add(s);
            System.out.println("成功加入");
            return true;
        }
    }
    public boolean removestu(int o) {
		for(Student ss: stuList){
            if(ss.sno==o){
                stuList.remove(ss);
                break ;
            }
        }
				return true;	
	}
}

class Tools {
    static ArrayList<Student> list1 = new ArrayList<Student>();// JAVA
    static ArrayList<Student> list2 = new ArrayList<Student>();// C
    static HashMap<String, ArrayList<Student>> mStu = new HashMap<String, ArrayList<Student>>();

    public static void group() {
        for (Student o: StudentManager.stuList) {
            if (o.smajor.equals("JAVA"))
                list1.add(o);
            else
                list2.add(o);
        }
    }

    public static void testSortor() {
        Collections.sort(list1);
        Collections.sort(list2);
        mStu.put("JAVA", list1);
        mStu.put("C", list2);
        System.out.println("*****************");
		System.out.println(mStu);
    }
}

public class test {
    public static void main(String[] args) {
        StudentManager stu = new StudentManager();
        stu.addStudent(new Student("小五", 10, "JAVA"));
        stu.addStudent(new Student("小六", 98, "C"));
        stu.addStudent(new Student("小七", 2, "C")); 
        stu.removestu(98);
        Tools.group();
        Tools.testSortor();
    }
    
}

